package com.example.demo.service.impl;

import com.example.demo.dao.HotelDao;
import com.example.demo.entity.Hotel;

import com.example.demo.service.HotelService;
import com.example.demo.vo.HotelVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HotelServiceImpl implements HotelService {

    private HotelDao hotelDao;
    @Autowired
    public void setHotelDao(HotelDao hotelDao) {
        this.hotelDao = hotelDao;
    }

    @Override
    public List<Hotel> getAllHotel() {
        return hotelDao.getAllHotel();
    }

    @Override
    public int addHotel(Hotel hotel) {
        return hotelDao.insert(hotel);
    }

    @Override
    public int updateHotel(Hotel hotel) {
        return hotelDao.update(hotel);
    }

    @Override
    public int deleteHotel(Integer id) {
        return hotelDao.delete(id);
    }

    @Override
    public PageInfo selectHotel(HotelVO hotelVO,int pageNo,int pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        List<Hotel> list = hotelDao.select(hotelVO);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public PageInfo getPageInfo(int pageNo, int pageSize) {
        //分页关键，必须写在第一行
        PageHelper.startPage(pageNo, pageSize);
        List<Hotel> list = hotelDao.getAllHotel();
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public String getImageName(int id) {
        return hotelDao.selectProp(id);
    }


}
